package action.config;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import component.ShowDailogComponent;
import constants.Constants;
import utils.GameUtils;

/**
 * @Auther syc.
 * @Date 2016/11/16 16:54.
 */
public class ConfigJSONEffectPathConfigAction extends AnAction {
    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Application application = ApplicationManager.getApplication();
        ShowDailogComponent component = application.getComponent(ShowDailogComponent.class);

        //get the json effect path
        String oldPath = GameUtils.getPropertyValue(anActionEvent, Constants.CONFIG_JSON_EFFECT_PATH_PRO_NAME);

        if (null == oldPath || oldPath.equals("")) {
            oldPath = GameUtils.getPropertyValue(anActionEvent, Constants.PROJECT_PATH_PRO_NAME) + Constants.RELATIVE_JSON_EFFECT_PATH;
            GameUtils.setGameProperties(anActionEvent, Constants.CONFIG_JSON_EFFECT_PATH_PRO_NAME, oldPath, "set the default effect path");
        }

        Project project = anActionEvent.getProject();
        String path = component.showInputDialog(project, "配置JSON数据生效目录为：" + oldPath +
                "\n请输入配置JSON数据生效目录：\n示例(..\\code\\server\\trunk\\json)", oldPath ,"config effect Path");

        if(null != path) {
            GameUtils.setGameProperties(anActionEvent, Constants.CONFIG_JSON_EFFECT_PATH_PRO_NAME, path, "modify the config effect path");
        }
    }
}
